package activity.servlet;

import activity.dao.Actdao;
import activity.entity.Activity;
import activity.utils.JBDCUlit2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

@WebServlet("/selectact")
public class selectAct extends HttpServlet {
    private static final long serialVersionUID = 1L;
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String inactid = req.getParameter("inactid");
        System.out.println("查询的账号:"+inactid);

        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        JBDCUlit2 db=new JBDCUlit2();

        Activity activity=new Activity();
        activity.setActid(inactid);
        Actdao dao=new Actdao();

        Connection conn=db.getConn();
        try {
            if (dao.selAct(conn,activity)!=null){
                System.out.println(activity);
                req.setAttribute("activity",dao.selAct(conn,activity));
                req.getRequestDispatcher("selactres.jsp").forward(req,resp);
            }else {
                out.println("<h1>活动不存在!</h1>");
                resp.setHeader("Refresh", "1;url=selact.jsp");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
